#include "StdAfx.h"
#include "UIRadioButton.h"
#include "UIGridImgPlus.h"
#include "UIGlobalStyle.h"
#include "UIMemDC.h"
#include <assert.h>
CUIRadioButton::CUIRadioButton( HWND hWnd ): CUIControl( hWnd )
{
    assert( BS_AUTORADIOBUTTON == ( GetStyle() & BS_AUTORADIOBUTTON ) );
    SetTransparent( TRUE );
}


CUIRadioButton::~CUIRadioButton( void )
{

}

void CUIRadioButton::OnDraw( HDC hDC )
{

    RECT rcClient = {0};
    GetButtonRect( rcClient );

    GetImage()->SetCurStatus( IMG_NORMAL );

    if ( IsEnable() )
    {
        if ( IsHot() )
        {
            GetImage()->SetCurStatus( IMG_HOVER );
        }

        if ( IsChecked() )
        {
            GetImage()->SetCurStatus( 4 );
        }
    }
    else
    {
        ::SetTextColor( hDC, GetTextColor() );
        GetImage()->SetCurStatus( IMG_DISABLE );
    }

    int y = ( rcClient.bottom - GetImage()->GetSize().cy ) / 2;
    GetImage()->SetPosition( 0, y );
    GetImage()->Draw( hDC );

    TCHAR sText[50] = {0};
    int iLen =::GetWindowText( GetHwnd(), sText, 50 );
    ::SetBkMode( hDC, TRANSPARENT );
    rcClient.left = GetImage()->GetSize().cx + 1;
    HFONT hOldFont = ( HFONT )::SelectObject( hDC, CUIGlobalStyle::GetFont() );
    ::DrawText( hDC, sText, iLen, &rcClient, DT_VCENTER | DT_SINGLELINE | DT_CENTER );
    ::SelectObject( hDC, hOldFont );
}

LRESULT CUIRadioButton::ProcessUIMsg( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    switch ( uMsg )
    {
    case BM_SETSTATE:
    {
        CUIControl::ProcessUIMsg( uMsg, wParam, lParam );
        Redraw();
        return 0;
    }
    }

    return CUIControl::ProcessUIMsg( uMsg, wParam, lParam );
}